import User from '../models/user';
import md5 from 'md5';
import { v4 as uuidv4 } from 'uuid';
export const loginService = {
  login: async (loginId: string, loginPwd: string) => {
    loginPwd = md5(loginPwd);
    const result = await User.findOne({ where: { loginId, loginPwd } });
    return result?.toJSON();
  },
  enroll: async (loginId: string, loginPwd: string, userId: string) => {
    loginPwd = md5(loginPwd);
    const result = await User.update({ loginId, loginPwd }, {
      where: { userId }
    });
    return result;
  },
  //添加新人
  addEveryMan: async () => {
    const userId: string = uuidv4().replace(/-/g, '');
    const result = await User.create({ userType: 'everyman', userId })
    console.log(result.toJSON());
    return result.toJSON();
  }
}